﻿<?php
require_once('../../../config.php');
 require_once($CFG->libdir . '/adminlib.php');
 require_once($CFG->dirroot . '/local/myplugin/lib.php');
require_once($CFG->dirroot . "/local/myplugin/forms.php");

require_login($SITE);

if (!is_siteadmin()) {
    print_error("vui lòng đăng nhập với quyền admin để thao tác");
}


global $DB;
$option=array();

/* Ket noi den file javascript - module.js */
$PAGE->requires->js_init_call('M.local_myplugin');	
$cssdir =  $CFG->wwwroot.'/local/myplugin/css/mycss.css';
echo '<link rel="stylesheet" href="'.$cssdir.'" type="text/css" media="screen" />';
//echo '<link rel="stylesheet" href="style.css" type="text/css" media="screen" />';

echo '<script src="../colorbox/jquery.min.js"></script>';

$jsdir =  $CFG->wwwroot.'/local/myplugin/module.js';
				echo '<script src="'.$jsdir.'"></script>';

/* Chuan bi trang web can hien thi */	
$url = new moodle_url($CFG->wwwroot.'local/myplugin/lo/view_lo.php');
$PAGE->set_url($url);
$PAGE->set_title('Add Academic Program');
$PAGE->set_heading('Add Academic Program');
$PAGE->set_pagelayout('standard');

//Them thanh menu ngang ung voi trang trong duong link
navigation_node::override_active_url(new moodle_url($CFG->wwwroot.'/local/myplugin/lo/view_lo.php', array('param'=>'value')));

echo $OUTPUT->header();

/* Viet doan code cua ban o day */

//add tab vào trang
$mylib = new learning_outcome_management();
//set tab hien tai

$mform = new form_view_lo();
$mform->display();
echo '<div id="lodiv"></div>';
echo '<div id="tree-div" style="overflow:auto; height:300px;width:250px;border:1px solid #c3daf9;"></div>';
$loader = new PhpExt_Tree_TreeLoader();
	$loader->setDataUrl("get-nodes.php");
	
	$tree = new PhpExt_Tree_TreePanel();
	$tree->setUseArrows(true)
		->setAnimate(true)
		->setEnableDd(true)
		->setContainerScroll(true)
		->setLoader($loader)
		->setAutoScroll(true);    

	$root = new PhpExt_Tree_AsyncTreeNode();
	$root->setText("PHP-Ext Examples")
		 ->setDraggable(false)
		 ->setId("examples");
		 
		
echo PhpExt_Ext::OnReady(
		$tree->getJavascript(false, "tree"),
		$root->getJavascript(false, "root"),
		$tree->setRootNode($root),
		$tree->render("tree-div"),
		$root->expand()	
	);
//kiem tra neu dc submitted thì làm gì
if ($fromform = $mform->get_data()) 
{
	





	// $program_id=$fromform->cblo_program;
	// $str= '<div id="treecontrol">
		// <a title="Collapse the entire tree below" href="#"> Collapse All</a> | 
		// <a title="Expand the entire tree below" href="#"> Expand All</a> | 
		// <a title="Toggle the tree below, opening closed branches, closing open branches" href="#">Toggle All</a>
	// </div><ul id="red" class="treeview-red">';
	// $los = $DB->get_records('learning_outcome', array('lo_level'=>'1', 'program_id'=>$program_id));
			// foreach ($los as $lo)
			// {
				// $str = $str.'<li title="<a href=\'#\'>Edit</a>  <a href=\'#\'>Delete</a>"> <span>'.$lo->lo_id.'  '.$lo->lo_name .'</span><ul>';
				// $str = $str.get_children_nodes($lo->lo_id).'</ul></li>';
			// }
	// echo $str.'</ul>';
	
}
function get_children_nodes($parent_id)
		{
			global $DB;
			$sql="SELECT * FROM mdl_learning_outcome where parent_lo_id='".$parent_id."'";
			$chuoi="";
			$children = $DB->get_records_sql($sql);
			foreach ($children as $child)
			{
				//$child->lo_id.'-';
				if($child->lo_id!='')
				{
					$chuoi = $chuoi.'<li><span>'.$child->lo_id.'  '.$child->lo_name .'</span><ul>';
					$chuoi = $chuoi.get_children_nodes($child->lo_id).'</ul></li>';
				}
				else
				{
					$chuoi = $chuoi.'<li><span>'.$child->lo_id.'  '.$child->lo_name .'</span></li>';
				}
			}
			return $chuoi;
		}
		

	


/*------Ket thuc doan code cua ban-------*/

echo $OUTPUT->footer();

